<?php 
namespace app\admin\controller;
use think\Controller;
use think\Session;
/**
* 登陆相关
*/
class Login extends Controller
{
	public function index()
	{

		return 'Login';
	}
	/**
	 * [后台登录]
	 * @Author   lessant@126.com
	 * @DateTime 2017-11-05T19:23:45+0800
	 * @return   [type]                   [description]
	 */
	public function login()
	{	
		$this->assign('title','后台登录');
		return $this->fetch();
	}
	/**
	 * [检验登录数据]
	 * @Author   lessant@126.com
	 * @DateTime 2017-11-05T20:51:19+0800
	 * @return   [type]                   [description]
	 */
	public function check_data()
	{
		$username = input('post.username');
		$password = input('post.password');
		if( empty($username) || empty($password) ){
			return ['error'=>'1','msg'=>'账户或密码不能为空'];
		}
		$res = db('admin')->where('username',$username)->where('password',md5($password))->find();
		if( $res ){
			//写session
			session('admin.username',$res['username']);
			session('admin.aid',$res['aid']);
			return ['error'=>'0','msg'=>'登录成功','url'=>url('admin/index/index')];
		}else{
			return ['error'=>'1','msg'=>'登录失败'];
		}
	}
	/**
	 * [退出登录]
	 * @Author   lessant@126.com
	 * @DateTime 2017-11-06T08:36:51+0800
	 * @return   [type]                   [description]
	 */
	public function logout()
	{
		session('admin',null);
		$url = url('admin/login/login');
		return $this->success('退出成功',$url);
	}
}


?>